package io.itit.ecp.admin.bootstrap.config;

import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@Profile({"dev", "sit", "erp"})
public class Swagger3Config {

    @Bean
    public Docket ecpMiniDocket() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("小程序接口")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("io.itit.ecp.admin.provide.action.controller.miniprogram"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket ecpVisualizingDocket() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("可视化平台")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("io.itit.ecp.admin.provide.action.controller.visualizing"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket ecpDocket() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("能碳平台")
                .apiInfo(apiInfo()).select()
                .apis(RequestHandlerSelectors.basePackage("io.itit.ecp"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket allDocket() {
        return new Docket(DocumentationType.OAS_30)
                .groupName("所有模块")
                .apiInfo(apiInfo()).select()
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("能源与碳排放管理平台接口文档")
                .description("能源与碳排放管理平台接口文档，仅限开发内部使用！")
                .contact(new Contact("Roy", "", "yangchunzhi@itit.io"))
                .version("V1.0")
                .build();
    }

    @Bean
    public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
        DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
        defaultAdvisorAutoProxyCreator.setUsePrefix(true);

        return defaultAdvisorAutoProxyCreator;

    }
}